//
//  EntertainmentVC.m
//  massage
//
//  Created by 李志权 on 2016/12/14.
//  Copyright © 2016年 李志权. All rights reserved.
//

#import "EntertainmentVC.h"
#import "massageVCCell.h"
#import "LieDetectionVC.h"

#import "LeftMenuView.h"
@interface EntertainmentVC ()<LeftMenuViewDelegate>
{
    NSMutableArray *arrayData;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) LeftMenuView *menuView;
@end

@implementation EntertainmentVC
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    UIWindow *window = [[UIApplication sharedApplication]keyWindow];
    self.menuView = [[[LeftMenuView alloc] init] initWithContainerView:window];
    self.menuView.menuViewDelegate = self;
    //NSLog(@"----LeftMenuView0---- %@",self.menuView);
    [window addSubview:self.menuView];
    self.menuView.menuViewDelegate = self;
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.menuView removeFromSuperview];
    [self.menuView.maskView removeFromSuperview];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle = NO;
    
    self.navigationItem.title = @"按摩";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"按摩_icon2"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemClick)];
    
    arrayData =[NSMutableArray arrayWithObjects:@{@"location":@"测谎",@"English":@"真假大检验",@"image":@"ic_entertainment0",@"selectedImage":@"ic_entertainment_selected0",@"is":@"0"},@{@"location":@"心动指数",@"English":@"男女配对",@"image":@"ic_entertainment1",@"selectedImage":@"ic_entertainment_selected1",@"is":@"0"},@{@"location":@"体质测试",@"English":@"身体素质大扫描",@"image":@"ic_entertainment2",@"selectedImage":@"ic_entertainment_selected2",@"is":@"0"}, nil];
    // Do any additional setup after loading the view from its nib.
}
- (void)leftBarButtonItemClick
{
    [UIView animateWithDuration:0.25 animations:^{
        self.menuView.X = 0;
    }];
}
#pragma mark - LeftMenuViewDelegate
- (void)LeftMenuViewActionIndex:(NSString *)vType{
    [Utils leftMenuClickIndex:vType];
    [self.menuView closeLeftView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (arrayData && arrayData.count) {
        return arrayData.count;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"massageVCCellID";
    massageVCCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        [tableView registerNib:[UINib nibWithNibName:@"massageVCCell" bundle:nil] forCellReuseIdentifier:cellID];
        cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    }
    if (arrayData && arrayData.count) {
        NSDictionary *dic =arrayData[indexPath.row];
        NSString *is = dic[@"is"];
        if ([is isEqualToString:@"0"]) {
            cell.image.image = PNGIMAGE(dic[@"image"]);
            cell.signImage.image = PNGIMAGE(@"选择设备_icon1");
            cell.selectedView.hidden = YES;
            cell.locationLabel.textColor = MAINBLUEGrayDark;
            cell.EnglishLabel.textColor = GrayLight;
            cell.line.hidden = NO;
            
        }
        else
        {
            cell.image.image = PNGIMAGE(dic[@"selectedImage"]);
            cell.signImage.image = PNGIMAGE(@"按摩_icon1");
            cell.selectedView.hidden = NO;
            cell.locationLabel.textColor = GreenColor;
            cell.EnglishLabel.textColor = GreenColor;
            cell.line.hidden = YES;
        }
        cell.locationLabel.text = dic[@"location"];
        cell.EnglishLabel.text =dic[@"English"];
        [cell.selectedView setShearRound:10 masksToBounds:YES borderWidth:3 borderColor:GreenColor];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:arrayData[indexPath.row]];
    [dic setObject:@"1" forKey:@"is"];
    [arrayData replaceObjectAtIndex:indexPath.row withObject:dic];
    
    for (int a = 0; a<arrayData.count; a++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:arrayData[a]];
        if (a==indexPath.row) {
            [dic setObject:@"1" forKey:@"is"];
        }
        else
        {
            [dic setObject:@"0" forKey:@"is"];
        }
        [arrayData replaceObjectAtIndex:a withObject:dic];
    }
    [tableView reloadData];
    NSUInteger indices[] = {0,indexPath.row-1};
    NSIndexPath *TIndexPath = [[NSIndexPath alloc]initWithIndexes:indices length:2];
    massageVCCell *Tcell = [tableView cellForRowAtIndexPath:TIndexPath];
    Tcell.line.hidden = YES;
    [self.navigationController pushViewController:[[LieDetectionVC alloc]init] animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
